package com.design.pattern.creational.singleton;

import java.io.Serializable;

/**
 * description
 *
 * @author RenQiQiang 2019/02/18 11:03
 */
public class HungrySingleton implements Serializable {

    private final static HungrySingleton hungrySingleton;

    static {
        //类加载时就初始化好
        hungrySingleton = new HungrySingleton();
    }
    private HungrySingleton(){
        if(hungrySingleton != null){
            throw new RuntimeException("单例禁止反射");
        }
    }

    public static HungrySingleton getInstance(){
        return hungrySingleton;
    }


    private Object readResolve(){
        return hungrySingleton;
    }
}
